
const { createWebAPIRequest } = require('../../util/util')

module.exports = [
  {
    /**
    * @api {get} /music/artists [获取歌手单曲]
    * @apiGroup Music
    * @apiPermission none
    * @apiDescription 调用此接口 , 传入歌手 id, 可获得歌手部分信息和热门歌曲
    * @apiParam {Number} id  id=6452
    */
    url: '/music/artists',
    method: 'get',
    request: (req, res) => {
      const cookie = req.get('Cookie') || ''
      const id = req.query.id
      const data = {
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        `/weapi/v1/artist/${id}`,
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  },
  {
    /**
    * @api {get} /music/artist/mv [艺术家-mv]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {Number} id  id
    * @apiParam {Number} [offset=0] 页
    * @apiParam {Number} [limit=30]  每页数量
    */
    url: '/music/artist/mv',
    method: 'get',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const id = req.query.id
      const data = {
        artistId: id,
        total: true,
        offset: req.query.offset || 0,
        limit: req.query.limit || 30,
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        `/weapi/artist/mvs`,
        'POST',
        data,
        cookie,
        musicReq => res.send(musicReq),
        err => res.status(500).send({err})
      )
    }
  },
  {
    /**
    * @api {get} /music/artist/desc [艺术家-信息]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {Number} id  id
    */
    url: '/music/artist/desc',
    method: 'get',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const id = req.query.id
      const data = {
        id,
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        `/weapi/artist/introduction`,
        'POST',
        data,
        cookie,
        musicReq => res.send(musicReq),
        err => res.status(500).send({err})
      )
    }
  },
  {
    /**
    * @api {get} /music/artist/album [获取歌手单曲]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {Number} id  id
    * @apiParam {Number} [offset=0] 页
    * @apiParam {Number} [limit=30]  每页数量
    */
    url: '/music/artist/album',
    method: 'get',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const id = req.query.id
      const data = {
        offset: req.query.offset || 0,
        total: true,
        limit: req.query.limit || 30,
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        `/weapi/artist/albums/${id}`,
        'POST',
        data,
        cookie,
        musicReq => res.send(musicReq),
        err => res.status(500).send({err})
      )
    }
  }
]
